    package BioClusterAction;
    
    import java.io.File;
    import java.io.IOException;
    
    import java.util.ArrayList;
    import java.util.Collections;
    import java.util.Scanner;
    
    
    public class ProcessBuilderTest {
        private static String process_name_array[] = new String[5];
    
        private static ProcessBuilder pb;
        private static Process p;
    
        /**
         * Trivial constructor.
         */
        public ProcessBuilderTest(String first_arg, String second_arg, 
                                  String third_arg, String fourth_arg, 
                                  String fifth_arg, String projectLink) {
            process_name_array[0] = first_arg;
            process_name_array[1] = second_arg;
            process_name_array[2] = third_arg;
            process_name_array[3] = fourth_arg;
            process_name_array[4] = fifth_arg;
            pb = new ProcessBuilder(process_name_array);
            pb.directory(new File(projectLink));
            pb.redirectErrorStream(true);
            this.startProcess();
        }
    
    
        /**
         * Starts the process of a process builder, gets the inputstream from the
         * process. Does not close until the process is completed.
         * 
         * @return Process the process started.
         */
        public void startProcess() {
            p = null;
            try {
                p = pb.start();
            } catch (IOException ioe) {
                System.out.println(ioe.getMessage());
                ioe.printStackTrace();
            }
            // get inputstream from process
            Scanner scan = new Scanner(p.getInputStream());
            // auxiliary string to show output on both std out
            String temp;
            // get input from scanner, send to std out
            while (scan.hasNext()) {
                temp = scan.next();
                System.out.print(temp + " ");
            }
            scan.close();
            // wait for process to terminate before exiting
    
            try {
                p.waitFor();
    
            } catch (InterruptedException e) {
                System.out.print("ERROR CODE VALUE N CRASH" + p);
                if (p != null) {
                    p.destroy();
    
                }
            }
    
        }
    
        public void endProcess() {
            p.destroy();
        }
    }
